package xdu.lz.stage2_design_pattern.chapter12_balking_pattern;

import java.io.IOException;

/**
 * 自己修改并保存的线程类
 */
public class CustomerThread extends Thread {

    private final BalkingData balkingData ;

    public CustomerThread(BalkingData balkingData) {
        super("Customer");
        this.balkingData = balkingData;
    }

    @Override
    public void run() {
        try {
            for (int i = 0; i < 20; i++) {
                //主动去做出改变
                balkingData.change("No"+i);
                //注意这里每次change都要save一下，否则数据会被后change的冲刷
                balkingData.save();
                Thread.sleep(100);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
